import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  // {
  //   path: '/phoneLogin',
  //   component: () => import('@/views/phoneLogin'),
  //   hidden: true
  // },
  {
    path: '/examLogin',
    component: () => import('@/views/examLogin'),
    hidden: true
  },
  {
    path: '/portalLogin',
    component: () => import('@/views/portalLogin'),
    hidden: true
  },
  {
    path: '/portal',
    component: () => import('@/views/portal/index'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/phoneLogin'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/phoneRegister',
    component: () => import('@/views/phoneRegister'),
    hidden: true
  },
  {
    path:'/forgetPassword',
    component: () => import('@/views/forgetPassword'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  }

]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  },
  {
    path: '/training/class/TrainingClass',
    name: '培训班级管理',
    component: Layout,
    permissions: ['TrainingClass:TrainingClass:list'],
    meta: {
      title: '培训班级管理',
      icon: 'class',
      visible: true,
      breadcrumb: false // 父路由不参与面包屑
    },
    children: [
      // 1. 班级设置
      {
        path: 'classSet/:classId/:id?',
        component: () => import('@/views/training/class/TrainingClass/classSet'),
        name: '班级设置',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '班级设置',
          icon: 'build',
          visible: true,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 明确面包屑层级（首页 -> 培训班级管理 -> 班级设置）
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '班级设置' } // null 表示当前页不跳转
          ]
        }
      },

      // 2. 班级学员
      {
        path: 'classStudents/:classId/:className/:handoverStatus/:trainingClassCode/:projectId?',
        component: () => import('@/views/training/class/TrainingClass/classStudents'),
        name: '班级学员',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '班级学员',
          icon: 'checkbox',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 独立面包屑层级
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '班级学员' }
          ]
        }
      },

      // 3. 实践预约情况
      {
        path: 'classSchedule/:classId/:className/:handoverStatus/:trainingClassCode?',
        component: () => import('@/views/training/class/TrainingClass/classSchedule'),
        name: '实践预约情况',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '实践预约情况',
          icon: 'color',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '实践预约情况' }
          ]
        }
      },

      // 4. 学员进出班管理
      {
        path: 'classStudentManagement/:classId/:className/:handoverStatus/:projectId/:trainingClassCode?',
        component: () => import('@/views/training/class/TrainingClass/classStudentManagement'),
        name: '学员进出班管理',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '学员进出班管理',
          icon: 'component',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '学员进出班管理' }
          ]
        }
      },

      // 5. 班级维护
      {
        path: 'classMaintenance/:classId/:className/:classStatus?',
        component: () => import('@/views/training/class/TrainingClass/classMaintenance'),
        name: '班级维护',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '班级维护',
          icon: 'edit',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '班级维护' }
          ]
        }
      },

      // 6. 班级数据
      {
        path: 'classData/:classId/:className/:handoverStatus/:trainingClassCode?',
        component: () => import('@/views/training/class/TrainingClass/classData'),
        name: '班级数据',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '班级数据',
          icon: 'component',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '班级数据' }
          ]
        }
      },

      // 7. 签到
      {
        path: 'classAttendance/:classId/:className/:handoverStatus/:trainingClassCode?',
        component: () => import('@/views/training/class/TrainingClass/classAttendance'),
        name: '签到',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '签到',
          icon: 'dashboard',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '签到' }
          ]
        }
      },

      // 8. 签到详情
      {
        path: 'attendanceRecord/:classId/:className/:classCheckinId/:trainingClassCode/:checkinTime/:checkinLocation?',
        component: () => import('@/views/training/class/TrainingClass/attendanceRecord'),
        name: '签到详情',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '签到详情',
          icon: 'button',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '签到详情' }
          ]
        }
      },

      // 9. 签到统计
      {
        path: 'attendanceTracking/:classId/:className/:trainingClassCode?',
        component: () => import('@/views/training/class/TrainingClass/attendanceTracking'),
        name: '签到统计',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '签到统计',
          icon: 'button',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '签到统计' }
          ]
        }
      },

      // 10. 班级考试
      {
        path: 'classExam/:classId/:className/:handoverStatus/:trainingClassCode?',
        component: () => import('@/views/training/class/TrainingClass/classExam'),
        name: '班级考试',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '班级考试',
          icon: 'drag',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '班级考试' }
          ]
        }
      },

      // 11. 学员个人考试
      {
        path: 'personalExam/:classId/:className/:name/:idCard/:trainingClassCode/:projectId/studentId',
        component: () => import('@/views/training/class/TrainingClass/personalExam'),
        name: '学员个人考试',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '学员个人考试',
          icon: 'code',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '学员个人考试' }
          ]
        }
      },

      // 12. 特设考试
      {
        path: 'specialExam/:classId/:className/:classStatus?',
        component: () => import('@/views/training/class/TrainingClass/specialExam'),
        name: '特设考试',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '特设考试',
          icon: 'client',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '特设考试' }
          ]
        }
      },

      // 13. 实践预约
      {
        path: 'practicalAppointment',
        component: () => import('@/views/training/class/TrainingClass/practicalAppointment'),
        name: '实践预约',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '实践预约',
          icon: 'client',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '实践预约' }
          ]
        }
      },

      // 13. 1+x项目
      {
        path: 'multipleProjects/:classId/:className/:classStatus?',
        component: () => import('@/views/training/class/TrainingClass/multipleProjects'),
        name: '1+x项目',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '1+x项目',
          icon: 'client',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '1+x项目' }
          ]
        }
      },
      // 14. 实践预约签到详情
      {
        path: 'practicalAppointmentAttendance/:practiceAppointmentId/:practicalProjectName/:practiceTime/:practicalTeacherName/:practiceAddress?',
        component: () => import('@/views/training/class/TrainingClass/practicalAppointmentAttendance'),
        name: '实践预约签到详情',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '实践预约签到详情',
          icon: 'button',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '实践预约签到详情' }
          ]
        }
      },

      // 15. 实践预约预约情况
      {
        path: 'practicalAppointmentTracking/:practiceAppointmentId/:practicalProjectName/:practiceTime/:practicalTeacherName/:practiceAddress?',
        component: () => import('@/views/training/class/TrainingClass/practicalAppointmentTracking'),
        name: '实践预约预约情况',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '实践预约预约情况',
          icon: 'button',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '实践预约预约情况' }
          ]
        }
      },

      // 16. 内训学员
      {
        path: 'internalStudents/:classId',
        component: () => import('@/views/training/class/TrainingClass/internalTraining/internalStudents'),
        name: '内训学员',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '内训学员',
          icon: 'checkbox',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 独立面包屑层级
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '内训学员' }
          ]
        }
      },

      // 17. 班级满意度
      {
        path: 'satisfactionSurvey/:classId?',
        component: () => import('@/views/training/class/TrainingClass/satisfactionSurvey'),
        name: '班级满意度',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '班级满意度',
          icon: 'checkbox',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 独立面包屑层级
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '班级满意度' }
          ]
        }
      },

      // 17. 内训班级维护
      {
        path: 'internalClassData/:classId?',
        component: () => import('@/views/training/class/TrainingClass/internalTraining/internalClassData'),
        name: '内训班级维护',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '内训班级维护',
          icon: 'checkbox',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 独立面包屑层级
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '内训班级维护' }
          ]
        }
      },

      // 18. 经营性班级证书
      {
        path: 'classCertificateOperational/:classId?',
        component: () => import('@/views/training/class/TrainingClass/classCertificateOperational'),
        name: '经营性班级证书',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '经营性班级证书',
          icon: 'checkbox',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 独立面包屑层级
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '经营性班级证书' }
          ]
        }
      },

      // 19. 特设班级证书
      {
        path: 'classCertificateSpecial/:classId?',
        component: () => import('@/views/training/class/TrainingClass/classCertificateSpecial'),
        name: '特设班级证书',
        permissions: ['TrainingClass:TrainingClass:list'],
        meta: {
          title: '特设班级证书',
          icon: 'checkbox',
          visible: false,
          activeMenu: '/training/class/TrainingClass',
          noCache: true,
          breadcrumb: true,
          // 独立面包屑层级
          breadcrumbList: [
            { path: '/dashboard', title: '首页' },
            { path: '/training/class/TrainingClass', title: '培训班级管理' },
            { path: null, title: '特设班级证书' }
          ]
        }
      },
    ]
  },


  //考试提交---考试结果
  {
    path: '/exam/',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        // path: 'result/:result/:canRetake/:canRetake?',
        path: 'result/:result/:canRetake/',
        component: () => import('@/views/examination/portalExam/ExamResult.vue'),
        name: 'ExamResult',
        meta: {
          title: '考试结果',
          icon: 'chart',
          hidden: true // 不在侧边栏显示
        }
      }
    ]
  },


   //考试提交---考试结果
  {
    path: '/exam/',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        // path: 'result/:result/:canRetake/:canRetake?',
        path: 'start/',
        component: () => import('@/views/examination/portalExam/index.vue'),
        name: 'ExamResult',
        meta: {
          title: '考试结果',
          icon: 'chart',
          hidden: true // 不在侧边栏显示
        }
      }
    ]
  },
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push
let routerReplace = Router.prototype.replace
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
